<?php
/* SVN FILE: $Id: reorder.php 127 2009-07-22 03:55:08Z supersmashbrothers $ */
/**
* ibMarket 2
* IP.Board 3.0
* Saving the new category order
*
* @author $Author: supersmashbrothers $
* @copyright $Copyright$
* @version $Revision: 127 $
* @lastrevision $Date: 2009-07-22 03:55:08 +0000 (Wed, 22 Jul 2009) $
* @modifiedby $LastChangedBy: supersmashbrothers $
* @lastmodified $LastChangedDate: 2009-07-22 03:55:08 +0000 (Wed, 22 Jul 2009) $
* @filesource $URL: http://ipb-ibmarket.googlecode.com/svn/ibmarket2/trunk/admin/applications_addon/other/ibmarket/modules_admin/categories/reorder.php $
*/


if ( ! defined( 'IN_ACP' ) )
{
	print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";
	exit();
}

class admin_ibmarket_categories_reorder extends ipsCommand
{
	/**
	 * Skin object
	 *
	 * @access	private
	 * @var		object			Skin templates
	 */
	private $html;
	
	/**
	 * Main class entry point
	 *
	 * @access	public
	 * @param	object		ipsRegistry reference
	 * @return	void		[Outputs to screen]
	 */
	public function doExecute( ipsRegistry $registry )
	{
		$this->registry->getClass('class_permissions')->checkPermissionAutoMsg( 'category_manage' );
		
		ipsRegistry::getClass('adminFunctions')->checkSecurityKey();
		
		if(!$this->request['parent'] || is_null(marketRegistry::getCategoryTree($this->request['parent'])))
		{
			$this->registry->output->silentRedirectWithMessage( $this->settings['base_url']."module=categories&amp;section=manage" );
		}
		
		$this->registry->getClass('class_localization')->loadLanguageFile( array( 'admin_categories' ) );
		
		foreach(marketRegistry::getCategoryTree($this->request['parent']) as $category)
		{
			$this->DB->update('market_categories', array('cat_order' => intval($this->request['category_order'][$category['cat_id']])),"cat_id=".$category['cat_id']);
		}
		
		$this->cache->rebuildCache('market_category','ibmarket');
		
		ipsRegistry::getClass('adminFunctions')->saveAdminLog( $this->lang->words['category_reorder_log'] );
		
		$this->registry->output->global_message = $this->lang->words['category_reordered'];
		$this->registry->output->silentRedirectWithMessage( $this->settings['base_url']."module=categories&amp;section=manage&amp;parent=".$this->request['parent'] );
	}
}
